<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style/css/common.css" type="text/css" />
<title>管理区域</title>
<SCRIPT src="style/js/jquery-1.3.2.min.js" type=text/javascript></SCRIPT>
<SCRIPT src="style/js/main.js" type=text/javascript></SCRIPT>
<SCRIPT src="style/js/jquery-ui-1.7.2.custom.min.js" type=text/javascript></SCRIPT>
<LINK href="style/css/ui-lightness/jquery-ui-1.8.8.custom.css" type=text/css rel=stylesheet>
<script language="javascript">
$(document).ready(function(){
	$(".cbg").hover(function(){$(this).css("background-color","#F3F8F7")},function(){$(this).css("background-color","")});
});
</script>
</head>

<body>
<div id="man_zone" style="border:none;">
  <div id="tabs">
	<ul>
		<li><a href="#tabs-1">用户列表</a></li>
		<li><a href="#tabs-2">用户组列表</a></li>
	</ul>
     <div id="tabs-1" style="padding-left:0.2em;padding-right:0.4em;">
     	<table width="99%" border="0" align="center"  cellpadding="3" cellspacing="1" class="table_style"><form action="index.php?m=user&a=add" method="post">
          <tr align="">
            <td>用户名:<input name="username" type="text" class="size" />
              密码      <input name="password" type="text"  class="size" />      <input name="" type="submit" value="增加" /> <input name="" id="mkpasswd" type="button" value="生成随机密码" /> <span id="passwd"></span></td>
            </tr></form>
        </table>
        <br />
        <table width="99%" border="0" align="center"  cellpadding="3" cellspacing="1" class="table_style">
          <tr align="center">
            <td>ID</td>
            <td>用户名</td>
            <td>用户等级</td>
            <td>注册时间</td>
            <td>上次登录时间</td>
            <td>操作</td>
          </tr>
          <%foreach item=val from=$users%>
          <tr id="tr_<%$val.id%>" align="center" class="cbg">
            <td><%$val.id%></td>
            <td><%$val.username%></td>
            <td><%$val.group.name%></td>
            <td><%$val.register_time|date_format:"%Y-%m-%d"%></td>
            <td><%$val.login_time|date_format:"%Y-%m-%d"%></td>
            <td>
                <a href="javascript:;" class="repass" id="<%$val.id%>" passwd="<%$val.password%>">修改密码</a> 
                <a href="index.php?m=user&amp;a=disper&id=<%$val.id%>">分配权限</a> 
                <a href="index.php?m=user&amp;a=delete&amp;id=<%$val.id%>&ajax=1" class="delete">删除</a>
            </td>
          </tr>
          <%/foreach%>
        </table>
     </div>
      <div id="tabs-2" style="padding-left:0.2em;padding-right:0.4em;">
      	<table width="99%" border="0" align="center"  cellpadding="3" cellspacing="1" class="table_style">
        <form action="index.php?m=group&a=add" method="post">
          <tr align="">
            <td>
            	组名:<input name="gname" type="text" class="size" />
              	所属站点:<select name="wid">
                <option value="">请选择站点</option>
                <%foreach item=val from=$websites%>
                <option value="<%$val.wid%>"><%$val.domain%></option>
                <%/foreach%>
                </select>
                <input name="submit" type="submit" value="增加" /></td>
            </tr></form>
        </table>
        <br />
          <%foreach item=val from=$websites%>
          <table width="99%" border="0" align=""  cellpadding="3" cellspacing="1" class="table_style drop" domain="<%$val.domain%>" wid="<%$val.wid%>">
              <tr align="" style="background-color:#F3F8F7;">
                <td style="padding-left:30px;"><%$val.domain%></td>
              </tr>
          </table>
          <%assign var=wid value=$val.wid%>
          <%if $wid%>
          <%foreach item=value from=$groups.$wid%>
          <table width="99%" border="0" align=""  cellpadding="3" cellspacing="1" class="table_style drag"  style="cursor:move" gid="<%$value.gid%>" gname="<%$value.gname%>" >
              <tr align="" style="">
                <td style="padding-left:60px;">|-- <a href="index.php?m=group&a=edit&gid=<%$value.gid%>"><%$value.gname%></a> <a href="index.php?m=group&a=delete&gid=<%$value.gid%>" class="delete"><img src="style/images/delete.png" width="10" height="10" border="0" /></a></td>
              </tr>
          </table>
          <%/foreach%>
          <%/if%>
          <%/foreach%>
        
     </div>
 </div>

</div>

<div id="repassBox" style="display:none;">
<input name="password" type="text" id="password" value="12" class="size" />
<input type="hidden" name="id" value="" id="id" />
</div>

<script language="javascript">
$("#mkpasswd").click(function(){
	$("#passwd").load("index.php?m=user&a=mkpasswd");
});
$( ".drag" ).draggable({ 
	revert: "invalid", 
	axis: "y",
	containment: "#containment-wrapper", 
	scroll: false,helper: "clone" ,
	start:function(){
		gid = $(this).attr("gid");
		gname = $(this).attr("gname");
	}
});
$( ".drop" ).droppable({
	activeClass: "ui-state-hover",
	hoverClass: "ui-state-active",
	drop: function( event, ui ) {
		var domain = $(this).attr("domain");
		var wid = $(this).attr("wid");
		var warn = "确定要把用户组 "+gname+" 复制到 "+domain+" 吗?";
	    if(confirm(warn)){
			window.location = "index.php?m=user&a=copy&gid="+gid+"&wid="+wid;
		} else return false;
	}
});
$(".repass").click(function(){
	var passwd = $(this).attr("passwd");
	var id = $(this).attr("id");
	$("#password").val(passwd);
	$("#id").val(id);
	$("#repassBox").dialog({
		show: "",
		hide: "",
		title:'请输入新密码',
		buttons: {
			"确定": function() {
				var passwd = $("#password").val(passwd);
				var id = $("#id").val();
				$.post("index.php?m=user&a=repass&ajax=1",{"password":passwd,"id":id},function(data){
					if (data == '1'){
						overBox('<span style="color:green;">修改成功</span>');
						setTimeout(function(){window.location.reload();}, 1000);
					}else {
						overBox('<span style="color:red;">修改失败,请联系管理员</span>');
					}
				});
				BoxRemove("#repassBox");
			},
			"关闭": function() {
				BoxRemove("#repassBox");
			}
		}
	});
});
</script>
</body>
</html>
